package com.topway.dsmflex.thread.handler;

import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;


import org.apache.log4j.Logger;

import com.topway.dsmflex.Log;
import com.topway.dsmflex.model.base.DataMonitorBean;
import com.topway.dsmflex.model.synchro.DataTableBean;
import com.topway.dsmflex.thread.services.AbstractSynchroServices;
import com.topway.dsmflex.util.ExpressionUtil;
import com.topway.dsmflex.util.JdbcHelp;

public class DataHandle extends Thread {
	
	protected SimpleDateFormat formatDate = new SimpleDateFormat(JdbcHelp.TIMESTAMP_FORMAT);
	protected SimpleDateFormat formatStamp= new SimpleDateFormat(JdbcHelp.TIMESTAMP_FORMAT);//TIMESTAMP
	protected SimpleDateFormat formatTime = new SimpleDateFormat(JdbcHelp.TIME_FORMAT);
	
	
	private static Logger log = Logger.getLogger(AbstractSynchroServices.class);
	
	public static int INSERT=1;
	public static int UPDATE=2;
	public static int INSERTUPDATE=3;
	
	private ResultSet rs = null;
	private Connection targetConn = null;
	private Connection sourceConn = null;
	
	private DataTableBean dt = null;
	private Map<String,Object> lobMap = null;
	
	
	private  PreparedStatement ps =null;
	private  PreparedStatement psUpdate = null;
	private  PreparedStatement psInsert = null;
	private PreparedStatement psTargetQuery = null;
	private  ResultSet targetRs = null;
	private List<String> keyName=null;
	private  List<String> columnSourceNameUpdate = null;
	private  List<String> columnSource = null;
	private Map<String,Integer> mapColumnType  = null;
	private int flagResult = 0;
	
	private Statement stmtCurrentSource =null;
	private Statement stmtCurrentTarget =null;
	
	private Map<String,String> mapColExpress = null;
	private Map<String,String> mapColExpressValue = new HashMap<String,String>();
	
	
	public DataHandle( Map<String,Integer> mapColumnType ,Connection targetConn,Connection sourceConn, DataTableBean dt,List<Map<String,String>> listMap)
	{
		this.targetConn = targetConn;
		this.sourceConn = sourceConn;
		this.mapColumnType = mapColumnType;
		this.dt = dt;
		
		  keyName = dt.getKeySource();
		  columnSourceNameUpdate = dt.getColumnSourceUpdate();
		  columnSource  = dt.getColumnSource();
		  
		  mapColExpress = dt.getMapColExpress();
		  
		  try {
			  
			  stmtCurrentTarget = targetConn.createStatement();
			  if(null!=sourceConn)
			  stmtCurrentSource = sourceConn.createStatement();
	
			  
				if(dt.getOperatorTarget().equals("INSERT"))
				{
					ps = targetConn.prepareStatement(dt.getInsertTargetSql());
				}
				else if(dt.getOperatorTarget().equals("INSERTUPDATE"))
				{
					  psInsert = targetConn.prepareStatement(dt.getInsertTargetSql());
					  psUpdate =targetConn.prepareStatement(dt.getUpdateTargetSql());
					  psTargetQuery = targetConn.prepareStatement(dt.getSelectTargetSql());
				}
				else if(dt.getOperatorTarget().equals("UPDATE"))
				{
				     ps =targetConn.prepareStatement(dt.getUpdateTargetSql());
				}
				else if(dt.getOperatorTarget().equals("DELETE"))
				{
				     ps =targetConn.prepareStatement(dt.getDeleteTargetSql());
				}
				
			
				
			} catch (Exception e) {
			e.printStackTrace();
			}
		  
	}
	
	
	/**
	 * 最后执行
	 * @param dt
	 * @param listMap
	 */
	public void setMapCoumnValue(DataTableBean dt, List<Map<String,String>> listMap)
	{
		String sql1 = null==dt.getUpdateSourceSql()?"":dt.getUpdateSourceSql();
		String sql2 = null==dt.getTargetExecuteSql()?"":dt.getTargetExecuteSql();

			 Map<String,String>  map = listMap.get(0);
				  for (Entry<String, String> entry : map.entrySet()) {
					  sql1 = sql1.replace("{"+entry.getKey()+"}",  entry.getValue());
					  sql2 = sql2.replace("{"+entry.getKey()+"}",  entry.getValue());
	  		 	}
				  dt.setUpdateSourceSql(sql1);
				  dt.setTargetExecuteSql(sql2);
				  log.debug(sql1);
				  log.debug(sql2);

	}
	
	
	
	public int exeDataHandle(List<Map<String,String>> listMap,Map<String,Object> lobMap)
	{
		try {
			
			this.lobMap = lobMap;
			if(dt.getOperatorTarget().equals("INSERT"))
			{
				flagResult=synchroInsertData(listMap);
			}
			else if(dt.getOperatorTarget().equals("INSERTUPDATE"))
			{
				flagResult=synchroInsertOrUpdateData(listMap);
			}
			else if(dt.getOperatorTarget().equals("UPDATE"))
			{
				flagResult= synchroUpdateData(listMap);
			}else if(dt.getOperatorTarget().equals("DELETE"))
			{
				flagResult= synchroDeleteData(listMap);
			}
			
			
			if((((dt.getPageIndex()-1)*dt.getPageSize()))<0)
			{
			  Log.info(dt.getName()+" 已经处理了    "+flagResult+" 条数据.....");
			  dt.propertyChange(DataMonitorBean.SIZE,"",""+flagResult);
			}
			else
			{
				  Log.info(dt.getName()+" 已经处理了   "+(((dt.getPageIndex()-1)*dt.getPageSize())+flagResult)+" 条数据.....");
				  dt.propertyChange(DataMonitorBean.SIZE,"",""+((((dt.getPageIndex()-1)*dt.getPageSize())+flagResult)));
			}
			
			
			//当前执行
			currentSourceSql(this.dt,listMap);
			currentTargetSql(this.dt,listMap);
			
			//最后执行
			setMapCoumnValue(dt,listMap);
			
			
			  
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return flagResult;
	}
	
	
	/**
	 * 并源行
	 * @param dt
	 * @param listMap
	 */
	  private void currentSourceSql(DataTableBean dt,List<Map<String,String>> mapList) throws SQLException
	  {
		  if(null!=dt.getCurrentSourceSql()&&!dt.getCurrentSourceSql().equals(""))
		  {
			  String currentSourceSql = dt.getCurrentSourceSql();
			  Map<String,String> map = null;
			  for (int i = 0; i < mapList.size(); i++) {
				  currentSourceSql = dt.getCurrentSourceSql();
				  map = mapList.get(i);
				  for (Entry<String, String> entry : map.entrySet()) {
					  currentSourceSql = currentSourceSql.replace("{"+entry.getKey()+"}",  entry.getValue());
	  		 	}
				  log.debug(currentSourceSql);
				  stmtCurrentSource.addBatch(currentSourceSql);
		
			  }
			  stmtCurrentSource.executeBatch();
//			  sourceConn.commit();
		  stmtCurrentSource.clearBatch();
		  }
	  }
	  
		/**
		 * 并行目标
		 * @param dt
		 * @param listMap
		 */
	  private void currentTargetSql(DataTableBean dt,List<Map<String,String>> mapList) throws SQLException
	  {
		
		  if(null!=dt.getCurrentTargetSql()&&!dt.getCurrentTargetSql().equals(""))
		  {
			  String currentTargetSql = dt.getCurrentTargetSql();
			  Map<String,String> map = null;
			  for (int i = 0; i < mapList.size(); i++) {
				  currentTargetSql = dt.getCurrentTargetSql();
				  map = mapList.get(i);
				  for (Entry<String, String> entry : map.entrySet()) {
					  currentTargetSql = currentTargetSql.replace("{"+entry.getKey()+"}", entry.getValue());
	  		 	}
				
				  stmtCurrentTarget.addBatch(currentTargetSql);
				  log.debug(currentTargetSql);
			  }
			  stmtCurrentTarget.executeBatch();
			//  targetConn.commit();
			  stmtCurrentTarget.clearBatch();
		  }
	  }
	  
	  
	  
	  
	  public int synchroInsertData(List<Map<String,String>> listMap) throws SQLException {
		  try {
			     flagResult = execPreparedStatement(ps,mapColumnType,listMap);
//			     Log.info(dt.getName()+" 已经提交"+(((dt.getPageIndex()-1)*dt.getPageSize())+flagResult)+" 条数据.....");
//				  dt.propertyChange(DataMonitorBean.SIZE,"",""+(((dt.getPageIndex()-1)*dt.getPageSize())+flagResult));
		} catch (Exception e) {
			log.error(e.getMessage());
			e.printStackTrace();
		}finally{
//			if (null != ps)
//				ps.close();
		}
		  return flagResult;
	  }
	  
	  public int synchroInsertOrUpdateData(List<Map<String,String>> listMap) throws SQLException {
		  try {
			  	flagResult = 0;
			     ps = psInsert;
			     boolean flag = false;
		 	     int exeCount = 0;
		 		  for (int k = 0; k < listMap.size(); k++) {
		 			 expressCodeReplaceValue(listMap.get(k), mapColExpress, mapColumnType,mapColExpressValue);
		 			 
					    	  ps = psInsert;
								for (int i = 0; i < keyName.size(); i++) {
										getPreparedStatement(psTargetQuery,listMap.get(k), i, mapColumnType.get(keyName.get(i)), keyName.get(i), 1);
									}
							targetRs = psTargetQuery.executeQuery();
					         if(null!=targetRs && targetRs.next())
					         {
					        	ps = psUpdate; 
					        	for (int i = 0; i < columnSourceNameUpdate.size(); i++) {
									getPreparedStatement(ps, listMap.get(k), i, mapColumnType.get(columnSourceNameUpdate.get(i)), columnSourceNameUpdate.get(i), 1);
								}
					        	for (int i = 0; i < keyName.size(); i++) {
									getPreparedStatement(ps, listMap.get(k), columnSourceNameUpdate.size(),mapColumnType.get(keyName.get(i)), keyName.get(i), 1+i);
								}
					         }else
					         {
						         for (int i = 0; i < columnSource.size(); i++) {
						        	 getPreparedStatement(ps, listMap.get(k), i,mapColumnType.get(columnSource.get(i)), columnSource.get(i), 1);
						         }
					         }
					         ps.addBatch();
					         ++exeCount;
					         if(exeCount>5000)
					         {
					        	 exeCount=0;
					        	 flagResult +=execClearBatch(psInsert);
					        	 flagResult +=execClearBatch(psUpdate);
					        	 flag = false;
					         }
					         flag = true;
		 		  }
						if (flag) {

				        	 flagResult +=execClearBatch(psInsert);
				        	 flagResult +=execClearBatch(psUpdate);
						}
//					     Log.info(dt.getName()+" 已经提交更新"+(((dt.getPageIndex()-1)*dt.getPageSize())+flagResult)+" 条数据.....");
//					     dt.propertyChange(DataMonitorBean.SIZE,"",""+(((dt.getPageIndex()-1)*dt.getPageSize())+flagResult));
		} catch (Exception e) {
			log.error(e.getMessage());
			e.printStackTrace();
		}finally{
//			if (null != rs)
//				rs.close();
//			if (null != targetRs)
//				targetRs.close();
//			if (null != psTargetQuery)
//				psTargetQuery.close();
//			if (null != psUpdate)
//				psUpdate.close();
//			if (null != psInsert)
//				psInsert.close();
		}
		return flagResult;		
	  }
	  
	  
	  public int synchroDeleteData(List<Map<String,String>> listMap) throws SQLException {
		  try {
			  			flagResult = 0;
				     boolean flag = false;
			 	     int exeCount = 0;
			 	    for (int k = 0; k < listMap.size(); k++) {
			 	    	expressCodeReplaceValue(listMap.get(k), mapColExpress, mapColumnType,mapColExpressValue);
			 	    	
								for (int i = 0; i < keyName.size(); i++) {
									getPreparedStatement(ps, listMap.get(k), i,mapColumnType.get(keyName.get(i)), keyName.get(i), 1);
								}
						         ps.addBatch();
						         ++exeCount;
						         if(exeCount>5000)
						         {
						        	 exeCount=0;
						        	 flagResult +=execClearBatch(ps);
						        	 flag = false;
						         }
						         flag = true;
						      }
							if (flag) {
					        	 flagResult +=execClearBatch(ps);
							}
//				Log.info(dt.getName()+" 已经删除"+(((dt.getPageIndex()-1)*dt.getPageSize())+flagResult)+" 条数据.....");
//				dt.propertyChange(DataMonitorBean.SIZE,"",""+(((dt.getPageIndex()-1)*dt.getPageSize())+flagResult));
		  } catch (Exception e) {
			log.error(e.getMessage());
			e.printStackTrace();
		}finally{
//			if (null != rs)
//				rs.close();
//			if (null != ps)
//				ps.close();
		}
		return flagResult;
	  }
	  
	  
	  
	  
	  public int synchroUpdateData(List<Map<String,String>> listMap) throws SQLException {
		  try {
			  			flagResult = 0;
				     boolean flag = false;
			 	     int exeCount = 0;
			 	    for (int k = 0; k < listMap.size(); k++) {
			 	    	
			 	    			expressCodeReplaceValue(listMap.get(k), mapColExpress, mapColumnType,mapColExpressValue);
			 	    	
			 	    			for (int i = 0; i < columnSourceNameUpdate.size(); i++) {
			 	    				getPreparedStatement(ps, listMap.get(k), i, mapColumnType.get(columnSourceNameUpdate.get(i)), columnSourceNameUpdate.get(i), 1);
								}
								for (int i = 0; i < keyName.size(); i++) {
									getPreparedStatement(ps, listMap.get(k), columnSourceNameUpdate.size(),mapColumnType.get(keyName.get(i)), keyName.get(i), 1+i);
								}
						         ps.addBatch();
						         ++exeCount;
						         if(exeCount>5000)
						         {
						        	 exeCount=0;
						        	 flagResult +=execClearBatch(ps);
						        	 flag = false;
						         }
						         flag = true;
						      }
							if (flag) {
					        	 flagResult +=execClearBatch(ps);
							}
//				Log.info(dt.getName()+" 已经更新"+(((dt.getPageIndex()-1)*dt.getPageSize())+flagResult)+" 条数据.....");
//			    dt.propertyChange(DataMonitorBean.SIZE,"",""+(((dt.getPageIndex()-1)*dt.getPageSize())+flagResult));

		  } catch (Exception e) {
			log.error(e.getMessage());
			e.printStackTrace();
		}finally{
//			if (null != rs)
//				rs.close();
//			if (null != ps)
//				ps.close();
		}
		return flagResult;
	  }
	  
	  
	  
	  public int execPreparedStatement(PreparedStatement ps, Map<String,Integer> mapColumnType,List<Map<String,String>> listMap)
	  {
		  flagResult = 0;
		  boolean flag = false;
	     int exeCount = 0;
	     int flagResult = 0;
		  try {
			    	  for (int i = 0; i < listMap.size(); i++) {
			    		  expressCodeReplaceValue(listMap.get(i), mapColExpress, mapColumnType,mapColExpressValue);
				         for (int j = 0; j < columnSource.size(); j++) {
				     	 	  getPreparedStatement(ps, listMap.get(i), j, mapColumnType.get(columnSource.get(j)), columnSource.get(j), 1);
			    		 	}
				         
			         ps.addBatch();
			         ++exeCount;
			         if(exeCount>5000)
			         {
			        	 exeCount=0;
			        	 flagResult +=execClearBatch(ps);
			        	 flag = false;
			         }
			         flag = true;
			 		
						}
				if (flag) {
					flagResult +=execClearBatch(ps);
				}
		} catch (Exception e) {
			log.error(e.getMessage());
			e.printStackTrace();
		}
		return flagResult;
	  }
	  
	  
	  public int execClearBatch(PreparedStatement ps ) throws SQLException
	  {	
			 int  [] reuslt = ps.executeBatch();
		      	 ps.clearBatch();
		      	 return reuslt.length;
	  }
	  

			  private PreparedStatement getPreparedStatement(PreparedStatement ps,Map<String,String> map,int i,int typeName,String  columnName,int index) throws SQLException
			  {
				  if (typeName == Types.DATE) {
		            //ps.setDate(i + index,ConvertDate(map,columnName,mapColExpressValue));
					 ps.setTimestamp(i + index,ConvertTimestamp(map,columnName,mapColExpressValue));
		            } else if (typeName == Types.TIMESTAMP) {
		            	   ps.setTimestamp(i + index,ConvertTimestamp(map,columnName,mapColExpressValue));
		            } else if (typeName == Types.TIME) {
		            	   ps.setTime(i + index,ConvertTime(map,columnName,mapColExpressValue));
		            } else if (typeName == Types.INTEGER) {
		            	   ps.setInt(i + index, ConvertInt(map,columnName,mapColExpressValue));
		            } else if (typeName == Types.BIGINT) {
		            	   ps.setLong(i + index, ConvertLong(map,columnName,mapColExpressValue));
		            } else if (typeName == Types.DECIMAL || typeName == Types.NUMERIC || typeName == Types.FLOAT) {
		            	   ps.setDouble(i + index, ConvertDouble(map,columnName,mapColExpressValue));
		            } else if (typeName == Types.BLOB) {
			              ps.setBlob(i + index,(Blob)(lobMap.get(map.get(columnName))));
			        } else if (typeName == Types.CLOB) {
			        		ps.setClob(i + index,(Clob)( lobMap.get(map.get(columnName))));
			        } else {
		            	   ps.setString(i + index, ConvertString(map,columnName,mapColExpressValue));
		            }
				return ps;
			  }  
			  
			 
			  public void close()
			  {
				  try {
					  if (null != ps)
						  ps.close();
						if (null != rs)
							rs.close();
						if (null != targetRs)
							targetRs.close();
						if (null != psTargetQuery)
							psTargetQuery.close();
						if (null != psUpdate)
							psUpdate.close();
						if (null != psInsert)
							psInsert.close();
					} catch (Exception e) {
						// TODO: handle exception
					}
			  }
	
			  
			  
			  private Map<String,String> expressCodeReplaceValue(Map<String,String> map,Map<String,String> mapColExpress, Map<String,Integer> mapColumnType,Map<String,String> mapColExpressValue) throws SQLException
			  {
				  if(mapColExpress.size()>0)
				  {
					  mapColExpressValue.clear();
					  mapColExpressValue.putAll(mapColExpress);
			    		 	for (Entry<String, Integer> mapColumnTypeEntry : mapColumnType.entrySet()) {
						    	for (Entry<String, String> entry : mapColExpressValue.entrySet()) {
//						    		if (mapColumnTypeEntry.getValue() == Types.DECIMAL || mapColumnTypeEntry.getValue() == Types.NUMERIC ||mapColumnTypeEntry.getValue() == Types.FLOAT|| mapColumnTypeEntry.getValue() == Types.INTEGER ||mapColumnTypeEntry.getValue() == Types.BIGINT)
						    			mapColExpressValue.put(entry.getKey(), entry.getValue().replace("{"+mapColumnTypeEntry.getKey()+"}", map.get(mapColumnTypeEntry.getKey()).replace("'", "\\'")));
//						    		else
//						    			mapColExpressValue.put(entry.getKey(), entry.getValue().replace("{"+mapColumnTypeEntry.getKey()+"}", "'"+( map.get(mapColumnTypeEntry.getKey()).replace("'", "\\'"))+"'"));
						    	}	
			    		 	}
				  }
		    	  return mapColExpressValue;
			  }
			  
			  
			  
			  private String ColExpress(String columnName,Map<String,String> mapColExpress)
			  {
				  if(null!=mapColExpress && mapColExpress.containsKey(columnName))	 
					  return ExpressionUtil.runExpre(mapColExpress.get(columnName));
				  return null;
			  }
			  
			  private Date ConvertDate(Map<String,String> rs,String columnName,Map<String,String> mapColExpress) throws SQLException
			  {
				  String value = ColExpress(columnName,mapColExpress);
				  java.sql.Date date = null;
				  if(null!=value)
		        	{
		        		try {
		            		date = new Date(formatDate.parse(value.replace("/", "-")).getTime());
						} catch (Exception e) {
							log.error(value+"表达式错误，反回值不能转化成java.sql.Date类型    列["+columnName+"]不能运行表达式");
							value="e";
						}
		        	}
		        	if(null==value||value.equals("e"))
			     	{
			     		if(rs.get(columnName).equals("null"))
			     			return null ;
			     		else
			     		{
			     			try {
			     				date= new Date(formatDate.parse(rs.get(columnName).replace("/", "-")).getTime());
							} catch (Exception e) {
								log.error(value+"日期格式错误 !");
								value="e";
							}
			     			
			     		}
			     	}
			      	return date;
			  }
			  
			  private Timestamp ConvertTimestamp(Map<String,String> rs,String columnName,Map<String,String> mapColExpress) throws SQLException
			  {
				  String value = ColExpress(columnName,mapColExpress);
				  java.sql.Timestamp stamp = null;
				  if(null!=value)
		        	{
		        		try {
		        			stamp = new Timestamp(formatStamp.parse(value.replace("/", "-")).getTime());
						} catch (Exception e) {
							log.error(value+"表达式错误，反回值不能转化成java.sql.Timestamp类型    列["+columnName+"]不能运行表达式");
							value="e";
						}
		        	}
		      	if(null==value||value.equals("e"))
			     	{
			     		if(rs.get(columnName).equals("null"))
			     			return null ;
			     		else
			     		{
			     			try {
			        			stamp = new Timestamp(formatStamp.parse(rs.get(columnName).replace("/", "-")).getTime());
							} catch (Exception e) {
								log.error(value+"" +
										"");
								value="e";
							}
			     		}
			     	}
			      	return stamp;
			  }
			  
			  private Time ConvertTime(Map<String,String> rs,String columnName,Map<String,String> mapColExpress) throws SQLException
			  {
				  String value = ColExpress(columnName,mapColExpress);
				  java.sql.Time stamp = null;
				  if(null!=value)
		        	{
		        		try {
		        			stamp = new Time(formatTime.parse(value.replace("/", "-")).getTime());
						} catch (Exception e) {
							log.error(value+"表达式错误，反回值不能转化成java.sql.Time类型    列["+columnName+"]不能运行表达式");
							value="e";
						}
		        	}
			      	if(null==value||value.equals("e"))
				     	{
				     		if(rs.get(columnName).equals("null"))
				     			return null ;
				     		else
				    		{
				     			try {
				        			stamp = new Time(formatTime.parse(rs.get(columnName).replace("/", "-")).getTime());
								} catch (Exception e) {
									log.error(value+"日期格式错误");
									value="e";
								}
				     		}
				     	}
				      	return stamp;
		       	 
			  }
			  private Integer ConvertInt(Map<String,String> rs,String columnName,Map<String,String> mapColExpress) throws SQLException
			  {
				  String value = ColExpress(columnName,mapColExpress);
				  Integer stamp = 0;
				  if(null!=value)
		        	{
		        		try {
		        			stamp= Integer.valueOf(value);	
						} catch (Exception e) {
							log.error(value+"表达式错误，反回值不能转化成java.sql.Int类型    列["+columnName+"]不能运行表达式");
							value="e";
						}
		        	}
			      	if(null==value||value.equals("e"))
			     	{
			     		if(rs.get(columnName).equals("null"))
			     			return Integer.valueOf("0");
			     		else
			     			return Integer.valueOf(rs.get(columnName));
			     	}
			      	return stamp;
			  }
			  private Long ConvertLong(Map<String,String> rs,String columnName,Map<String,String> mapColExpress) throws SQLException
			  {
				  String value = ColExpress(columnName,mapColExpress);
				  long stamp = 0;
				  if(null!=value)
		        	{
		        		try {
		        			stamp= Long.valueOf(value);	
						} catch (Exception e) {
							log.error(value+"表达式错误，反回值不能转化成java.sql.Long类型    列["+columnName+"]不能运行表达式");
							value="e";
						}
		        	}
			      	if(null==value||value.equals("e"))
			     	{
			     		if(rs.get(columnName).equals("null"))
			     			return Long.valueOf("0") ;
			     		else
			     			return  Long.valueOf(rs.get(columnName));
			     	}
			      	return stamp;
		       	 
			  }
			  
			  private Double ConvertDouble(Map<String,String> rs,String columnName,Map<String,String> mapColExpress) throws SQLException
			  {
				  String value = ColExpress(columnName,mapColExpress);
				  double stamp = 0;
			    	if(null!=value)
		        	{
		        		try {
		        			stamp= Double.valueOf(value);	
						} catch (Exception e) {
							log.error(value+"表达式错误，反回值不能转化成java.sql.Double类型    列["+columnName+"]不能运行表达式");
							value="e";
						}
		        	}
			     	if(null==value||value.equals("e"))
			     	{
			     		if(rs.get(columnName).equals("null"))
			     			return Double.valueOf("0");
			     		else
			     			return Double.valueOf(rs.get(columnName));
			     	}
			        return stamp;
		       	 
			  }
			  private String ConvertString(Map<String,String> rs,String columnName,Map<String,String> mapColExpress) throws SQLException
			  {
				  String value = ColExpress(columnName,mapColExpress);
			     	if(null==value)
			     	{
			     		if(rs.get(columnName).equals("null"))
			     			return "" ;
			     		else
			     			value= rs.get(columnName);
			     	}
			        return value;
			  }
			  
			  public static void main(String[] args) throws ParseException {
					SimpleDateFormat formatDate = new SimpleDateFormat(JdbcHelp.TIMESTAMP_FORMAT);
					Date d = new Date(formatDate.parse("2013-06-21 03:30:00").getTime());
					System.out.println(formatDate.format(d));
					String a = "03211";
					String b = "032";
					if(a.equals(b))
					{
						System.out.println("a");
					}

			}
			  

}
